
var app = angular.module('myApp', ['ionic', 'myApp.services', 'ngAnimate', 'ui.router', 'ngSanitize']);

    app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {



        $httpProvider.defaults.headers.common = {};
        $httpProvider.defaults.headers.put = {};
        $httpProvider.defaults.headers.patch = {};
        $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
        $httpProvider.defaults.transformRequest = [ function(data) {
            var param = function(obj) {
                var query = '' ;
                var name, value, fullSubName, subName, subValue, innerObj, i;

                for (name in obj) {
                    value = obj[name];

                    if (value instanceof Array) {
                        for (i = 0; i < value.length; ++i) {
                            subValue = value[i];
                            fullSubName = name + '[' + i + ']' ;
                            innerObj = {};
                            innerObj[fullSubName] = subValue;
                            query += param(innerObj) + '&';
                        }
                    } else if (value instanceof Object) {
                        for (subName in value) {
                            subValue = value[subName];
                            fullSubName = name + '.' + subName;
                            innerObj = {};
                            innerObj[fullSubName] = subValue;
                            query += param(innerObj) + '&';
                        }
                    } else if (value !== undefined && value !== null) {
                        query += encodeURIComponent(name) + '='
                            + encodeURIComponent(value) + '&';
                    }
                }

                return query.length ? query.substr(0, query.length - 1) : query;
            };

            return angular.isObject(data) && String(data) !== '[object File]'
                ? param(data)
                : data;
        }];


        

        $urlRouterProvider.otherwise('/mainPage');
        $stateProvider
            //首页
            .state('mainPage', {
                url: '/mainPage',
                cache:false,
                templateUrl: 'template/mainPage.html',
                controller: 'mainPageCtrl'
            })
            //我的薪资
            .state('salary/salaryList', {
                url: '/salary/salaryList',
                cache:false,
                templateUrl: 'template/salary/salaryList.html',
                controller: 'salaryListCtrl'
            })
            .state('salary/salaryInquiries', {
                url: '/salary/salaryInquiries',
                cache:false,
                templateUrl: 'template/salary/salaryInquiries.html',
                controller: 'salaryInquiriesCtrl'
            })
            .state('salary/cardChoose', {
                url: '/salary/cardChoose',
                cache:false,
                templateUrl: 'template/salary/cardChoose.html',
                controller: 'cardChooseCtrl'
            })
            .state('salary/salaryFlockCheck', {
                url: '/salary/salaryFlockCheck',
                cache:false,
                templateUrl: 'template/salary/salaryFlockCheck.html',
                controller: 'salaryFlockCheckCtrl'
            })
            .state('salary/salaryFlockResult', {
                url: '/salary/salaryFlockResult',
                cache:false,
                templateUrl: 'template/salary/salaryFlockResult.html',
                controller: 'salaryFlockResultCtrl'
            })
            .state('salary/tradDetail', {
                url: '/salary/tradDetail',
                cache:false,
                templateUrl: 'template/salary/tradDetail.html',
                controller: 'tradDetailCtrl'
            })
            //我的消息
            .state('new/tradInformation', {
                url: '/new/tradInformation',
                templateUrl: 'template/new/tradInformation.html',
                controller: 'tradInformationCtrl'
            })
            //我的企业
            .state('company/myCompany', {
                url: '/company/myCompany',
                templateUrl: 'template/company/myCompany.html',
                controller: 'myCompanyCtrl'
            })
            //在线审批
            .state('approval/approvalList', {
                url: '/approval/approvalList',
                templateUrl: 'template/approval/approvalList.html',
                controller: 'approvalListCtrl'
            })
            .state('approval/approvalApplication', {
                url: '/approval/approvalApplication',
                templateUrl: 'template/approval/approvalApplication.html',
                controller: 'approvalApplicationCtrl'
            })
            //通讯录
            .state('contact/contactList', {
                url: '/contact/contactList',
                templateUrl: 'template/contact/contactList.html',
                controller: 'contactListCtrl'
            })
            .state('contact/personalDetail', {
                url: '/contact/personalDetail',
                templateUrl: 'template/contact/personalDetail.html',
                controller: 'personalDetailCtrl'
            })
            .state('contact/addContact', {
                url: '/contact/addContact',
                templateUrl: 'template/contact/addContact.html',
                controller: 'addContactCtrl'
            })
            //工作管理
            .state('work/workManage', {
                url: '/work/workManage',
                cache:false,
                templateUrl: 'template/work/workManage.html',
                controller: 'workManageCtrl'
            })
            .state('work/workAdd', {
                url: '/work/workAdd',
                cache:false,
                templateUrl: 'template/work/workAdd.html',
                controller: 'workAddCtrl'
            })
            .state('work/approvalProgress', {
                url: '/work/approvalProgress',
                cache:false,
                templateUrl: 'template/work/approvalProgress.html',
                controller: 'approvalProgressCtrl'
            })
            .state('work/waitApproval', {
                url: '/work/waitApproval',
                cache:false,
                templateUrl: 'template/work/waitApproval.html',
                controller: 'waitApprovalCtrl'
            })
            .state('work/workReport', {
                url: '/work/workReport',
                cache:false,
                templateUrl: 'template/work/workReport.html',
                controller: 'workReportCtrl'
            })
            .state('work/applicationType', {
                url: '/work/applicationType',
                cache:false,
                templateUrl: 'template/work/applicationType.html',
                controller: 'applicationTypeCtrl'
            })



    }).run(function($ionicPlatform, $rootScope, $location, $ionicHistory) {
            //$ionicPlatform.ready(function() {
            //    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
            //    // for form inputs).
            //    // The reason we default this to hidden is that native apps don't usually show an accessory bar, at
            //    // least on iOS. It's a dead giveaway that an app is using a Web View. However, it's sometimes
            //    // useful especially with forms, though we would prefer giving the user a little more room
            //    // to interact with the app.
            //    if (window.cordova && window.cordova.plugins.Keyboard) {
            //        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            //        cordova.plugins.Keyboard.disableScroll(true);
            //    }
            //    if (window.StatusBar) {
            //        // Set the statusbar to use the default style, tweak this to
            //        // remove the status bar on iOS or change it to use white instead of dark colors.
            //        StatusBar.styleDefault();
            //    }
            //});
        //页面跳转的方法
        $rootScope.goPage = function(path){
            $location.path(path);
            // window.location.reload();
        };

        $rootScope.goPrevious = function () {
            $ionicHistory.goBack();
        }


    });


